{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pprint import pprint\n",
    "from IPython.display import display\n",
    "from hamilton import driver\n",
    "\n",
    "import lancedb\n",
    "import pyarrow as pa\n",
    "import __init__ as lancedb_vdb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Note: Hamilton collects completely anonymous data about usage. This will help us improve Hamilton over time. See https://github.com/apache/hamilton#usage-analytics--data-privacy for details.\n"
     ]
    },
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.43.0 (0)\n",
       " -->\n",
       "<!-- Title: %3 Pages: 1 -->\n",
       "<svg width=\"728pt\" height=\"595pt\"\n",
       " viewBox=\"0.00 0.00 728.00 595.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 591)\">\n",
       "<title>%3</title>\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-591 724,-591 724,4 -4,4\"/>\n",
       "<g id=\"clust1\" class=\"cluster\">\n",
       "<title>cluster__legend</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"8,-447 8,-579 104,-579 104,-447 8,-447\"/>\n",
       "<text text-anchor=\"middle\" x=\"56\" y=\"-563.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Legend</text>\n",
       "</g>\n",
       "<!-- reset -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>reset</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M465.5,-547C465.5,-547 425.5,-547 425.5,-547 419.5,-547 413.5,-541 413.5,-535 413.5,-535 413.5,-495 413.5,-495 413.5,-489 419.5,-483 425.5,-483 425.5,-483 465.5,-483 465.5,-483 471.5,-483 477.5,-489 477.5,-495 477.5,-495 477.5,-535 477.5,-535 477.5,-541 471.5,-547 465.5,-547\"/>\n",
       "<text text-anchor=\"start\" x=\"424.5\" y=\"-525.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">reset</text>\n",
       "<text text-anchor=\"start\" x=\"431.5\" y=\"-497.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">Dict</text>\n",
       "</g>\n",
       "<!-- vector_search -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>vector_search</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M701,-418C701,-418 593,-418 593,-418 587,-418 581,-412 581,-406 581,-406 581,-366 581,-366 581,-360 587,-354 593,-354 593,-354 701,-354 701,-354 707,-354 713,-360 713,-366 713,-366 713,-406 713,-406 713,-412 707,-418 701,-418\"/>\n",
       "<text text-anchor=\"start\" x=\"592\" y=\"-396.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">vector_search</text>\n",
       "<text text-anchor=\"start\" x=\"608.5\" y=\"-368.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
       "</g>\n",
       "<!-- insert -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>insert</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M669,-309C669,-309 625,-309 625,-309 619,-309 613,-303 613,-297 613,-297 613,-257 613,-257 613,-251 619,-245 625,-245 625,-245 669,-245 669,-245 675,-245 681,-251 681,-257 681,-257 681,-297 681,-297 681,-303 675,-309 669,-309\"/>\n",
       "<text text-anchor=\"start\" x=\"624\" y=\"-287.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">insert</text>\n",
       "<text text-anchor=\"start\" x=\"633\" y=\"-259.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">Dict</text>\n",
       "</g>\n",
       "<!-- table_ref -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>table_ref</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M483,-254C483,-254 408,-254 408,-254 402,-254 396,-248 396,-242 396,-242 396,-202 396,-202 396,-196 402,-190 408,-190 408,-190 483,-190 483,-190 489,-190 495,-196 495,-202 495,-202 495,-242 495,-242 495,-248 489,-254 483,-254\"/>\n",
       "<text text-anchor=\"start\" x=\"410.5\" y=\"-232.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">table_ref</text>\n",
       "<text text-anchor=\"start\" x=\"407\" y=\"-204.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">LanceTable</text>\n",
       "</g>\n",
       "<!-- table_ref&#45;&gt;vector_search -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>table_ref&#45;&gt;vector_search</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M495.15,-234.74C512.4,-241.07 530.98,-250.2 545,-263 565.41,-281.63 557.29,-295.99 574,-318 581.63,-328.05 590.8,-337.92 600.01,-346.9\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"597.71,-349.54 607.37,-353.89 602.53,-344.46 597.71,-349.54\"/>\n",
       "</g>\n",
       "<!-- table_ref&#45;&gt;insert -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>table_ref&#45;&gt;insert</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M495.05,-235.38C528.04,-244.48 571.28,-256.4 603.03,-265.15\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"602.33,-268.59 612.9,-267.87 604.19,-261.84 602.33,-268.59\"/>\n",
       "</g>\n",
       "<!-- delete -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>delete</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M671.5,-195C671.5,-195 622.5,-195 622.5,-195 616.5,-195 610.5,-189 610.5,-183 610.5,-183 610.5,-143 610.5,-143 610.5,-137 616.5,-131 622.5,-131 622.5,-131 671.5,-131 671.5,-131 677.5,-131 683.5,-137 683.5,-143 683.5,-143 683.5,-183 683.5,-183 683.5,-189 677.5,-195 671.5,-195\"/>\n",
       "<text text-anchor=\"start\" x=\"621.5\" y=\"-173.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">delete</text>\n",
       "<text text-anchor=\"start\" x=\"633\" y=\"-145.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">Dict</text>\n",
       "</g>\n",
       "<!-- table_ref&#45;&gt;delete -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>table_ref&#45;&gt;delete</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M495.05,-207.64C527.21,-198.13 569.11,-185.74 600.6,-176.43\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"601.84,-179.71 610.44,-173.52 599.85,-173 601.84,-179.71\"/>\n",
       "</g>\n",
       "<!-- full_text_search -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>full_text_search</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M708,-107C708,-107 586,-107 586,-107 580,-107 574,-101 574,-95 574,-95 574,-55 574,-55 574,-49 580,-43 586,-43 586,-43 708,-43 708,-43 714,-43 720,-49 720,-55 720,-55 720,-95 720,-95 720,-101 714,-107 708,-107\"/>\n",
       "<text text-anchor=\"start\" x=\"585\" y=\"-85.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">full_text_search</text>\n",
       "<text text-anchor=\"start\" x=\"608.5\" y=\"-57.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
       "</g>\n",
       "<!-- table_ref&#45;&gt;full_text_search -->\n",
       "<g id=\"edge11\" class=\"edge\">\n",
       "<title>table_ref&#45;&gt;full_text_search</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M495.05,-208.99C512.39,-202.49 531.06,-193.12 545,-180 565.99,-160.25 554.82,-143.51 574,-122 576.61,-119.07 579.44,-116.26 582.42,-113.55\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"584.71,-116.2 590.09,-107.07 580.19,-110.85 584.71,-116.2\"/>\n",
       "</g>\n",
       "<!-- client -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>client</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M273.5,-447C273.5,-447 176.5,-447 176.5,-447 170.5,-447 164.5,-441 164.5,-435 164.5,-435 164.5,-395 164.5,-395 164.5,-389 170.5,-383 176.5,-383 176.5,-383 273.5,-383 273.5,-383 279.5,-383 285.5,-389 285.5,-395 285.5,-395 285.5,-435 285.5,-435 285.5,-441 279.5,-447 273.5,-447\"/>\n",
       "<text text-anchor=\"start\" x=\"203\" y=\"-425.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">client</text>\n",
       "<text text-anchor=\"start\" x=\"175.5\" y=\"-397.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DBConnection</text>\n",
       "</g>\n",
       "<!-- client&#45;&gt;reset -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>client&#45;&gt;reset</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M285.77,-445.3C304.9,-454.75 326.23,-465.04 346,-474 364.79,-482.52 385.87,-491.39 403.7,-498.69\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"402.65,-502.04 413.23,-502.57 405.29,-495.55 402.65,-502.04\"/>\n",
       "</g>\n",
       "<!-- client&#45;&gt;table_ref -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>client&#45;&gt;table_ref</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M244.52,-382.81C265.39,-348.99 302.19,-296.2 346,-263 357.99,-253.91 372.3,-246.46 386.24,-240.53\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"387.84,-243.65 395.79,-236.66 385.21,-237.16 387.84,-243.65\"/>\n",
       "</g>\n",
       "<!-- _vector_search_inputs -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>_vector_search_inputs</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"545,-464.5 346,-464.5 346,-335.5 545,-335.5 545,-464.5\"/>\n",
       "<text text-anchor=\"start\" x=\"368\" y=\"-437.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">vector_query</text>\n",
       "<text text-anchor=\"start\" x=\"480.5\" y=\"-437.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Union</text>\n",
       "<text text-anchor=\"start\" x=\"384\" y=\"-416.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">columns</text>\n",
       "<text text-anchor=\"start\" x=\"471.5\" y=\"-416.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Optional</text>\n",
       "<text text-anchor=\"start\" x=\"361.5\" y=\"-395.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">prefilter_where</text>\n",
       "<text text-anchor=\"start\" x=\"486\" y=\"-395.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">bool</text>\n",
       "<text text-anchor=\"start\" x=\"398\" y=\"-374.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">limit</text>\n",
       "<text text-anchor=\"start\" x=\"491.5\" y=\"-374.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">int</text>\n",
       "<text text-anchor=\"start\" x=\"392\" y=\"-353.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">where</text>\n",
       "<text text-anchor=\"start\" x=\"471.5\" y=\"-353.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Optional</text>\n",
       "</g>\n",
       "<!-- _vector_search_inputs&#45;&gt;vector_search -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>_vector_search_inputs&#45;&gt;vector_search</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M545.08,-393.08C553.74,-392.47 562.4,-391.87 570.82,-391.28\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"571.21,-394.76 580.94,-390.57 570.72,-387.77 571.21,-394.76\"/>\n",
       "</g>\n",
       "<!-- _insert_inputs -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>_insert_inputs</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"499.5,-317.5 391.5,-317.5 391.5,-272.5 499.5,-272.5 499.5,-317.5\"/>\n",
       "<text text-anchor=\"start\" x=\"406.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">data</text>\n",
       "<text text-anchor=\"start\" x=\"443.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Union</text>\n",
       "</g>\n",
       "<!-- _insert_inputs&#45;&gt;insert -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>_insert_inputs&#45;&gt;insert</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M499.7,-290.2C531.92,-287.29 572.48,-283.63 602.72,-280.9\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"603.31,-284.37 612.96,-279.98 602.68,-277.39 603.31,-284.37\"/>\n",
       "</g>\n",
       "<!-- _table_ref_inputs -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>_table_ref_inputs</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"317,-265.5 133,-265.5 133,-178.5 317,-178.5 317,-265.5\"/>\n",
       "<text text-anchor=\"start\" x=\"174\" y=\"-238.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">schema</text>\n",
       "<text text-anchor=\"start\" x=\"261\" y=\"-238.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Union</text>\n",
       "<text text-anchor=\"start\" x=\"161\" y=\"-217.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">table_name</text>\n",
       "<text text-anchor=\"start\" x=\"272\" y=\"-217.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">str</text>\n",
       "<text text-anchor=\"start\" x=\"148\" y=\"-196.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">overwrite_table</text>\n",
       "<text text-anchor=\"start\" x=\"266.5\" y=\"-196.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">bool</text>\n",
       "</g>\n",
       "<!-- _table_ref_inputs&#45;&gt;table_ref -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>_table_ref_inputs&#45;&gt;table_ref</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M317.08,-222C340.33,-222 364.7,-222 385.84,-222\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"385.93,-225.5 395.93,-222 385.93,-218.5 385.93,-225.5\"/>\n",
       "</g>\n",
       "<!-- _delete_inputs -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>_delete_inputs</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"535.5,-171.5 355.5,-171.5 355.5,-126.5 535.5,-126.5 535.5,-171.5\"/>\n",
       "<text text-anchor=\"start\" x=\"370.5\" y=\"-144.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">delete_expression</text>\n",
       "<text text-anchor=\"start\" x=\"501.5\" y=\"-144.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">str</text>\n",
       "</g>\n",
       "<!-- _delete_inputs&#45;&gt;delete -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>_delete_inputs&#45;&gt;delete</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M535.75,-155.26C557.98,-156.82 580.92,-158.43 600.08,-159.78\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"600.08,-163.29 610.3,-160.49 600.57,-156.3 600.08,-163.29\"/>\n",
       "</g>\n",
       "<!-- _client_inputs -->\n",
       "<g id=\"node12\" class=\"node\">\n",
       "<title>_client_inputs</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"104,-437.5 8,-437.5 8,-392.5 104,-392.5 104,-437.5\"/>\n",
       "<text text-anchor=\"start\" x=\"23\" y=\"-410.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">uri</text>\n",
       "<text text-anchor=\"start\" x=\"48\" y=\"-410.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Union</text>\n",
       "</g>\n",
       "<!-- _client_inputs&#45;&gt;client -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>_client_inputs&#45;&gt;client</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M104.41,-415C119.82,-415 137.26,-415 153.97,-415\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"154.25,-418.5 164.25,-415 154.25,-411.5 154.25,-418.5\"/>\n",
       "</g>\n",
       "<!-- _full_text_search_inputs -->\n",
       "<g id=\"node13\" class=\"node\">\n",
       "<title>_full_text_search_inputs</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"544.5,-108 346.5,-108 346.5,0 544.5,0 544.5,-108\"/>\n",
       "<text text-anchor=\"start\" x=\"391.5\" y=\"-81.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">where</text>\n",
       "<text text-anchor=\"start\" x=\"470.5\" y=\"-81.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Optional</text>\n",
       "<text text-anchor=\"start\" x=\"361.5\" y=\"-60.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">full_text_query</text>\n",
       "<text text-anchor=\"start\" x=\"490.5\" y=\"-60.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">str</text>\n",
       "<text text-anchor=\"start\" x=\"397.5\" y=\"-39.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">limit</text>\n",
       "<text text-anchor=\"start\" x=\"490.5\" y=\"-39.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">int</text>\n",
       "<text text-anchor=\"start\" x=\"362.5\" y=\"-18.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">full_text_index</text>\n",
       "<text text-anchor=\"start\" x=\"479.5\" y=\"-18.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Union</text>\n",
       "</g>\n",
       "<!-- _full_text_search_inputs&#45;&gt;full_text_search -->\n",
       "<g id=\"edge12\" class=\"edge\">\n",
       "<title>_full_text_search_inputs&#45;&gt;full_text_search</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M544.79,-64.35C551.09,-65.01 557.4,-65.67 563.61,-66.33\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"563.66,-69.85 573.97,-67.42 564.39,-62.89 563.66,-69.85\"/>\n",
       "</g>\n",
       "<!-- input -->\n",
       "<g id=\"node14\" class=\"node\">\n",
       "<title>input</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"85.5,-547.5 26.5,-547.5 26.5,-510.5 85.5,-510.5 85.5,-547.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"56\" y=\"-525.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input</text>\n",
       "</g>\n",
       "<!-- function -->\n",
       "<g id=\"node15\" class=\"node\">\n",
       "<title>function</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M84,-492.5C84,-492.5 28,-492.5 28,-492.5 22,-492.5 16,-486.5 16,-480.5 16,-480.5 16,-467.5 16,-467.5 16,-461.5 22,-455.5 28,-455.5 28,-455.5 84,-455.5 84,-455.5 90,-455.5 96,-461.5 96,-467.5 96,-467.5 96,-480.5 96,-480.5 96,-486.5 90,-492.5 84,-492.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"56\" y=\"-470.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">function</text>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x7f9366849270>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dr = (\n",
    "    driver.Builder()\n",
    "    .with_modules(lancedb_vdb)\n",
    "    .build()\n",
    ")\n",
    "\n",
    "display(dr.display_all_functions(None))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'reset': {'tables_dropped': ['demo_table']}}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dr.execute(final_vars=[\"reset\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'table': LanceTable(demo_table), 'n_rows_added': 2}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_id</th>\n",
       "      <th>source</th>\n",
       "      <th>vector</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>Google Search</td>\n",
       "      <td>[0.0, 2.0, 11.0, 22.0]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Bing Search</td>\n",
       "      <td>[11.0, 23.0, 2.0, 87.0]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   source_id         source                   vector\n",
       "0          0  Google Search   [0.0, 2.0, 11.0, 22.0]\n",
       "1          1    Bing Search  [11.0, 23.0, 2.0, 87.0]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "final_vars = [\"insert\"]\n",
    "\n",
    "inputs = dict(\n",
    "    table_name=\"demo_table\",\n",
    "    schema=pa.schema([\n",
    "        (\"source_id\", pa.int64()),\n",
    "        (\"source\", pa.string()),\n",
    "        (\"vector\", lancedb.schema.vector(4)),\n",
    "    ]),\n",
    "    data=[\n",
    "        {\"source_id\": 0, \"source\": \"Google Search\", \"vector\": [0., 2., 11., 22.]},\n",
    "        {\"source_id\": 1, \"source\": \"Bing Search\", \"vector\": [11., 23., 2., 87.]}\n",
    "    ],\n",
    ")\n",
    "\n",
    "res = dr.execute(\n",
    "    final_vars=final_vars,\n",
    "    inputs=inputs,\n",
    ")\n",
    "\n",
    "display(\n",
    "    res[\"insert\"],\n",
    "    res[\"insert\"][\"table\"].to_pandas(),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source_id</th>\n",
       "      <th>source</th>\n",
       "      <th>vector</th>\n",
       "      <th>_distance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>Google Search</td>\n",
       "      <td>[0.0, 2.0, 11.0, 22.0]</td>\n",
       "      <td>485.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Bing Search</td>\n",
       "      <td>[11.0, 23.0, 2.0, 87.0]</td>\n",
       "      <td>7747.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   source_id         source                   vector  _distance\n",
       "0          0  Google Search   [0.0, 2.0, 11.0, 22.0]      485.0\n",
       "1          1    Bing Search  [11.0, 23.0, 2.0, 87.0]     7747.0"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "final_vars = [\"vector_search\"]\n",
    "\n",
    "inputs = dict(\n",
    "    table_name=\"demo_table\",\n",
    "    vector_query=[2., 2., 2., 2.],\n",
    ")\n",
    "\n",
    "res = dr.execute(\n",
    "    final_vars=final_vars,\n",
    "    inputs=inputs,\n",
    ")\n",
    "\n",
    "display(res[\"vector_search\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>source</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Bing Search</td>\n",
       "      <td>0.693147</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        source     score\n",
       "0  Bing Search  0.693147"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "res = dr.execute(\n",
    "    final_vars=[\"full_text_search\"],\n",
    "    inputs=dict(\n",
    "        table_name=\"demo_table\",\n",
    "        full_text_index=[\"source\"],\n",
    "        full_text_query=\"Bing\",\n",
    "    ),\n",
    ")\n",
    "\n",
    "display(res[\"full_text_search\"])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
